package com.hqyj.mana.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hqyj.mana.dao.FileManagementMapper;
import com.hqyj.mana.dao.FileTypeMapper;
import com.hqyj.mana.pojo.ContractManagement;
import com.hqyj.mana.pojo.FileManagement;
import com.hqyj.mana.pojo.FileType;
import com.hqyj.mana.service.FileManagementService;

@Service
public  class FileManagementServiceImpl implements FileManagementService {	
	@Autowired
	FileManagementMapper mapper;
	@Autowired
	FileTypeMapper fileTypeMapper;
	@Override
	@Transactional
	public JSONArray selectAllFileManagement() {
		// TODO Auto-generated method stub
		JSONArray ja = new JSONArray();
		List<FileType> typeList = fileTypeMapper.selectAll();
		for(int i =0;i<typeList.size();i++){
			JSONObject jb = new JSONObject();
			jb.put("type", typeList.get(i).getTypeName());
			List<FileManagement> list = mapper.selectFile(typeList.get(i).getTypeId());
			jb.put("file", list);
			ja.add(jb);
		}
		
		return ja;
	}
	public boolean add(FileManagement user) {
		//System.out.println(user.getBasicVage());
		if(mapper.insertSelective(user)>0){
			return true;
		}
		return false;
	}
	@Override
	public boolean update(FileManagement user) {
		if(mapper.updateByPrimaryKeySelective(user)>0){
			return true;
		}
		return false;
	}
	@Override
	public boolean del(Integer id) {
		if(mapper.deleteByPrimaryKey(id)>0){
			return true;
		}
		return false;
	}
	@Override
	public HashMap<String, Object> hashCode(Object user) {
		// TODO Auto-generated method stub
		return null;
	}
	


	}


